package com.fas.system.controller;

import com.fas.common.core.controller.BaseController;
import com.fas.common.core.domain.AjaxResult;
import com.fas.common.core.page.TableDataInfo;
import com.fas.system.domain.FasFacilitiesType;
import com.fas.system.service.IFasFacilitiesTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 *  设施类型表 Controller
 *
 * @date 2022-06-30
 */
@Api(tags = "设施类型")
@RestController
@RequestMapping("/system/facilities/type")
public class FasFacilitiesTypeController extends BaseController {

    @Resource
    private IFasFacilitiesTypeService fasFacilitiesTypeService;

    @ApiOperation(value = "查询设施类型列表")
    @GetMapping("/findList")
    public TableDataInfo findList(FasFacilitiesType fasFacilitiesType,Integer pageNum,Integer pageSize){
        startPage();
        return getDataTable(fasFacilitiesTypeService.findList(fasFacilitiesType));
    }

    @ApiOperation(value = "新增设施类型")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FasFacilitiesType fasFacilitiesType){
        // 默认启用
        if(Objects.isNull(fasFacilitiesType)){
            fasFacilitiesType.setDelFlag("0");
        }
        return toAjax(fasFacilitiesTypeService.addFasFacilitiesType(fasFacilitiesType));
    }

    @ApiOperation(value = "修改设施类型")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody FasFacilitiesType fasFacilitiesType){
        return toAjax(fasFacilitiesTypeService.updateFasFacilitiesType(fasFacilitiesType));
    }

    @ApiOperation(value = "删除设施类型")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        return fasFacilitiesTypeService.deleteFasFacilitiesType(id);
    }

    @ApiOperation(value = "批量启用设施类型")
    @GetMapping("/batchUpdateDelFlag")
    public AjaxResult batchUpdateDelFlag(@RequestParam("ids") List<Integer> ids,@RequestParam("delFlag") String delFlag){
        return toAjax(fasFacilitiesTypeService.batchUpdateDelFlag(ids,delFlag));
    }

}
